/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ImportRest.java
 *
 * Created on 18 Φεβ 2012, 1:57:22 πμ
 * gimoutsakis
 */
package handax.GUI;

import handax.controller.DBManager;
import handax.entities.Restaurant;
import handax.utilities.Utils;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.ImageObserver;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * 
 */
public class ImportRest extends javax.swing.JFrame {
    
    //author gimoutsakis
    //μεθοδος καθαρισμου πεδίων
    private void clearForm() { 
        
        // Αρχικοποίηση όλων των πεδίων της φόρμας
        nameTextField.setText("");
        addressTextField.setText("");
        areaComboBox.setSelectedIndex(0);
        phoneTextField.setText("");
        jComboBox2.setSelectedIndex(0);
        jTextField2.setText("");
        jTextField3.setText("");
        jComboBox1.setSelectedIndex(0);
        imageLabel.setIcon(null);
         
        
        
    }
    

    //αναφορά τύπου Admin
    private Admin root;
    
    /** Creates new form ImportRest */
    public ImportRest() {
        initComponents();
    }
    
    //μέθοδος για να ορίσουμε το αρχικό παράθυρο
    public void setRoot(Admin root){
        this.root=root;
    }
    
    //Δημιουργία DBManager για επικοινωνία με την βάση
    DBManager db =new DBManager();

    //Δημιουργία entity Restaurant
    Restaurant a =new Restaurant();
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        headerLabel = new javax.swing.JLabel();
        menuPanel = new javax.swing.JPanel();
        importButton = new javax.swing.JButton();
        modifyButton = new javax.swing.JButton();
        deleteButton = new javax.swing.JButton();
        exitButton = new javax.swing.JButton();
        categoryList = new javax.swing.JPanel();
        addressLabel = new javax.swing.JLabel();
        areaLabel = new javax.swing.JLabel();
        phoneLabel = new javax.swing.JLabel();
        categoryLabel = new javax.swing.JLabel();
        infoResLabel = new javax.swing.JLabel();
        descrLabel = new javax.swing.JLabel();
        priceRangeLabel = new javax.swing.JLabel();
        photoLabel = new javax.swing.JLabel();
        addPhotoButton = new javax.swing.JButton();
        resName = new javax.swing.JLabel();
        nameTextField = new javax.swing.JTextField();
        addressTextField = new javax.swing.JTextField();
        phoneTextField = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jComboBox1 = new javax.swing.JComboBox();
        areaComboBox = new javax.swing.JComboBox();
        jComboBox2 = new javax.swing.JComboBox();
        updateButton = new javax.swing.JButton();
        imageLabel = new javax.swing.JLabel();
        infoLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(handax.HandaxApp.class).getContext().getResourceMap(ImportRest.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        setResizable(false);

        headerLabel.setIcon(resourceMap.getIcon("headerLabel.icon")); // NOI18N
        headerLabel.setText(resourceMap.getString("headerLabel.text")); // NOI18N
        headerLabel.setName("headerLabel"); // NOI18N

        menuPanel.setBackground(resourceMap.getColor("menuPanel.background")); // NOI18N
        menuPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        menuPanel.setName("menuPanel"); // NOI18N

        importButton.setText(resourceMap.getString("importButton.text")); // NOI18N
        importButton.setEnabled(false);
        importButton.setName("importButton"); // NOI18N
        importButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                importButtonActionPerformed(evt);
            }
        });

        modifyButton.setText(resourceMap.getString("modifyButton.text")); // NOI18N
        modifyButton.setEnabled(false);
        modifyButton.setName("modifyButton"); // NOI18N

        deleteButton.setText(resourceMap.getString("deleteButton.text")); // NOI18N
        deleteButton.setEnabled(false);
        deleteButton.setName("deleteButton"); // NOI18N

        exitButton.setText(resourceMap.getString("exitButton.text")); // NOI18N
        exitButton.setName("exitButton"); // NOI18N
        exitButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout menuPanelLayout = new javax.swing.GroupLayout(menuPanel);
        menuPanel.setLayout(menuPanelLayout);
        menuPanelLayout.setHorizontalGroup(
            menuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, menuPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(menuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(exitButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
                    .addComponent(deleteButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
                    .addComponent(importButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE)
                    .addComponent(modifyButton, javax.swing.GroupLayout.DEFAULT_SIZE, 219, Short.MAX_VALUE))
                .addContainerGap())
        );
        menuPanelLayout.setVerticalGroup(
            menuPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(menuPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(importButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(modifyButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(deleteButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(exitButton)
                .addContainerGap(424, Short.MAX_VALUE))
        );

        categoryList.setName("categoryList"); // NOI18N

        addressLabel.setFont(resourceMap.getFont("infoResLabel.font")); // NOI18N
        addressLabel.setText(resourceMap.getString("addressLabel.text")); // NOI18N
        addressLabel.setName("addressLabel"); // NOI18N

        areaLabel.setFont(resourceMap.getFont("infoResLabel.font")); // NOI18N
        areaLabel.setText(resourceMap.getString("areaLabel.text")); // NOI18N
        areaLabel.setName("areaLabel"); // NOI18N

        phoneLabel.setFont(resourceMap.getFont("infoResLabel.font")); // NOI18N
        phoneLabel.setText(resourceMap.getString("phoneLabel.text")); // NOI18N
        phoneLabel.setName("phoneLabel"); // NOI18N

        categoryLabel.setFont(resourceMap.getFont("infoResLabel.font")); // NOI18N
        categoryLabel.setText(resourceMap.getString("categoryLabel.text")); // NOI18N
        categoryLabel.setName("categoryLabel"); // NOI18N

        infoResLabel.setFont(resourceMap.getFont("infoResLabel.font")); // NOI18N
        infoResLabel.setText(resourceMap.getString("infoResLabel.text")); // NOI18N
        infoResLabel.setName("infoResLabel"); // NOI18N

        descrLabel.setFont(resourceMap.getFont("infoResLabel.font")); // NOI18N
        descrLabel.setText(resourceMap.getString("descrLabel.text")); // NOI18N
        descrLabel.setName("descrLabel"); // NOI18N

        priceRangeLabel.setFont(resourceMap.getFont("photoLabel.font")); // NOI18N
        priceRangeLabel.setText(resourceMap.getString("priceRangeLabel.text")); // NOI18N
        priceRangeLabel.setName("priceRangeLabel"); // NOI18N

        photoLabel.setFont(resourceMap.getFont("photoLabel.font")); // NOI18N
        photoLabel.setText(resourceMap.getString("photoLabel.text")); // NOI18N
        photoLabel.setName("photoLabel"); // NOI18N

        addPhotoButton.setText(resourceMap.getString("addPhotoButton.text")); // NOI18N
        addPhotoButton.setName("addPhotoButton"); // NOI18N
        addPhotoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addPhotoButtonActionPerformed(evt);
            }
        });

        resName.setFont(resourceMap.getFont("resName.font")); // NOI18N
        resName.setText(resourceMap.getString("resName.text")); // NOI18N
        resName.setName("resName"); // NOI18N

        nameTextField.setText(resourceMap.getString("nameTextField.text")); // NOI18N
        nameTextField.setName("nameTextField"); // NOI18N

        addressTextField.setText(resourceMap.getString("addressTextField.text")); // NOI18N
        addressTextField.setName("addressTextField"); // NOI18N

        phoneTextField.setText(resourceMap.getString("phoneTextField.text")); // NOI18N
        phoneTextField.setName("phoneTextField"); // NOI18N

        jTextField2.setText(resourceMap.getString("jTextField2.text")); // NOI18N
        jTextField2.setName("jTextField2"); // NOI18N

        jTextField3.setText(resourceMap.getString("jTextField3.text")); // NOI18N
        jTextField3.setName("jTextField3"); // NOI18N

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { ".", "1.12€ - 20€", "2.15€ - 20€", "3.15€ - 25€", "4.20€ - 30€", "5.20€ - 35€", "6.35€ - 50€" }));
        jComboBox1.setName("jComboBox1"); // NOI18N

        areaComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { ".", "1.Κνωσσός", "2. Αρκαλοχώρι", "3. Ζαρός", "4. Μοίρες", "5. Μάλια", "6. Αρχάνες", "7. Αρχάνεςι", "8. Αρχάνες", "9. Αρχάνες", "10. Αρχάνες" }));
        areaComboBox.setName("areaComboBox"); // NOI18N

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { ".", "1.Ελληνική Κουζίνα", "2.Ιταλική Κουζίνα", "3.Κινέζικη Κουζίνα", "4.Μεσογειακή Κουζίνα", "5.Ουζερί", "6.Μεζεδοπωλείο", "7.Ψαροταβέρνα", "8.Ταβέρνα", "9.Bar-Restaurant" }));
        jComboBox2.setName("jComboBox2"); // NOI18N

        updateButton.setText(resourceMap.getString("updateButton.text")); // NOI18N
        updateButton.setActionCommand(resourceMap.getString("updateButton.actionCommand")); // NOI18N
        updateButton.setName("updateButton"); // NOI18N
        updateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateButtonActionPerformed(evt);
            }
        });

        imageLabel.setText(resourceMap.getString("imageLabel.text")); // NOI18N
        imageLabel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        imageLabel.setName("imageLabel"); // NOI18N

        javax.swing.GroupLayout categoryListLayout = new javax.swing.GroupLayout(categoryList);
        categoryList.setLayout(categoryListLayout);
        categoryListLayout.setHorizontalGroup(
            categoryListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(categoryListLayout.createSequentialGroup()
                .addGroup(categoryListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(categoryListLayout.createSequentialGroup()
                        .addGap(70, 70, 70)
                        .addGroup(categoryListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(descrLabel)
                            .addComponent(infoResLabel)
                            .addComponent(addressLabel)
                            .addComponent(resName)
                            .addComponent(areaLabel)
                            .addComponent(phoneLabel)
                            .addComponent(categoryLabel)
                            .addGroup(categoryListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(photoLabel)
                                .addComponent(priceRangeLabel)))
                        .addGap(18, 18, 18)
                        .addGroup(categoryListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(categoryListLayout.createSequentialGroup()
                                .addGap(2, 2, 2)
                                .addComponent(imageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(addPhotoButton, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(categoryListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jComboBox2, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(phoneTextField, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(areaComboBox, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(addressTextField, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(nameTextField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE))
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 306, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(categoryListLayout.createSequentialGroup()
                        .addGap(250, 250, 250)
                        .addComponent(updateButton)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        categoryListLayout.setVerticalGroup(
            categoryListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(categoryListLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(categoryListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(resName)
                    .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addGroup(categoryListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(addressLabel)
                    .addComponent(addressTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(categoryListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(areaLabel)
                    .addComponent(areaComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(categoryListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(phoneTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(phoneLabel))
                .addGroup(categoryListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(categoryListLayout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addComponent(categoryLabel))
                    .addGroup(categoryListLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(categoryListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(infoResLabel)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(categoryListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(descrLabel)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(categoryListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(priceRangeLabel)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(categoryListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(photoLabel)
                    .addComponent(imageLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(addPhotoButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(updateButton))
        );

        infoLabel.setFont(resourceMap.getFont("infoLabel.font")); // NOI18N
        infoLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        infoLabel.setText(resourceMap.getString("infoLabel.text")); // NOI18N
        infoLabel.setName("infoLabel"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(menuPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(categoryList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(infoLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 544, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addComponent(headerLabel)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(headerLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(infoLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(categoryList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(menuPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void importButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_importButtonActionPerformed

    private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitButtonActionPerformed
        
        //επανεμφάνιση αρχικού παραθύρου
        root.setVisible(true);
        
        //κατέστρεψε το παράθυρο εισαγωγής
        dispose();
        
    }//GEN-LAST:event_exitButtonActionPerformed

    //gimoutsakis
    
private void updateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateButtonActionPerformed
   
    //ελεχγος άν υπάρχει σύνδεση με την βάση
if(!db.connectedToDatabase)
          {JOptionPane.showMessageDialog(new JFrame(), "Δέν υπάρχει σύνδεση με την Βάση!!");}
     
      try{
          
              
          //Στοιχεία
          String name=nameTextField.getText().trim();
          String address=addressTextField.getText().trim();
          int area=areaComboBox.getSelectedIndex();
          String phone=phoneTextField.getText().trim();
          int categ=jComboBox2.getSelectedIndex();
          String info=jTextField2.getText().trim();
          String perigrafi=jTextField3.getText().trim();
          int timi=jComboBox1.getSelectedIndex();
           
          //Δημιουργία entity Restaurant
          //Restaurant a =new Restaurant();
          
          //ορισμός στοιχείων
                     a.setRestName(name);
                     a.setAddress(address);
                     a.setPhone(phone);
                     a.setArea(area);
                     a.setCategory(categ);
                     a.setInfo(info);
                     a.setDescr(perigrafi);
                     a.setPrice(timi);
                     
          
                     //έλεγχος αν έχουν συμπληρωθεί ολα τα πεδία        
                     if("".equals(name) || "".equals(address)|| 
                             "".equals(phone)||"".equals(info)||
                             "".equals(perigrafi)||area==0||categ==0||timi==0){
            
                         throw new Exception("Πρέπει να συμπληρωθούν όλα τα πεδία!");   
            
                     }
                     
                     
                     //Ελεγχος για το αν υπάρχει το ίδιο τηλέφωνο και όνομα στην Βάση πετάει μήνυμα σε περίπτωση που υπάρχει
                     
                        for (int i = 0; i < db.retrieveAllRests().size(); i++)
                     {
                        if (a.getRestName().equals(db.retrieveAllRests().get(i).getRestName())   &&   a.getPhone().equals(db.retrieveAllRests().get(i).getPhone())) 
                             
                          
                          
                         { JOptionPane.showMessageDialog(new JFrame(), "Υπάρχει ήδη αυτό το όνομα με αυτο το τηλέφωνο!");
                              clearForm();       //μέθοδος καθαρισμού πεδίων
                               return  ;  }
                                                                      
                         
                     }
                     
                     //ερωτηση επιβεβαιωσης για την καταχωρηση αν δεν ειναι 
                     //σωστη ο χρηστης επιλεγει να επιστρέψει
                     int choice = JOptionPane.showConfirmDialog(this,
                                                   "Να καταχωρηθούν τα στοιχεία;",
                                                   "Επιβεβαίωση καταχώρησης",
                                                   JOptionPane.YES_NO_OPTION);
                     if (choice != 0){
                            return;
                     }
                     
                 //καταχωρηση με μηνυμα επιβεβαιωσης           
                 db.storeRestaurant(a) ;         
                 clearForm();    // καθαρισμός πεδίων μετα την καταχώρηση
                 JOptionPane.showMessageDialog(new JFrame(), "Επιτυχής καταχώρηση");
                
        {
            System.out.println("καταχωρήθηκε-μηνυμα κονσολας");
        }
          
        }catch (Exception ex){
            
                JOptionPane.showMessageDialog(new JFrame(), "Πρέπει να συμπληρωθούν όλα τα πεδία!");
            }

}//GEN-LAST:event_updateButtonActionPerformed

    private void addPhotoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPhotoButtonActionPerformed
        
            //Δημιουργία ενός jFileChooser
            JFileChooser fl=new JFileChooser();
            
            //άνοιγμα παραθύρου επιλογής αρχείου
            int returnval=fl.showOpenDialog(this);
            
            //αν επιλεχθεί εικόνα τότε ενημερώνει το imgLabel
            //και το path στην βάση
            if(returnval==fl.APPROVE_OPTION){
            //αποθήκευση προορισμού του αρχείου
            String dest=fl.getSelectedFile().getAbsolutePath();
            
            //δημιουργία εικόνας από τον προορισμό
            Image img=Toolkit.getDefaultToolkit().getImage(dest);
            
            //δημιουργία εικονιδίου από την εικόνα
            ImageIcon i=new ImageIcon(img);
            
            //δημιουργία ImageObserver
            ImageObserver io = null;
            
            //δημιουργία καινούριου εικονιδίου 
            //με προσαρμοσμένη διάσταση
            Icon ic=Utils.scale(img, 150.0, io);
            
            //τοποθέτηση εικονιδίου στο jLabel
            imageLabel.setIcon(ic);
            
            a.setPhoto(dest);
            }
            
    }//GEN-LAST:event_addPhotoButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ImportRest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ImportRest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ImportRest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ImportRest.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ImportRest().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addPhotoButton;
    private javax.swing.JLabel addressLabel;
    private javax.swing.JTextField addressTextField;
    private javax.swing.JComboBox areaComboBox;
    private javax.swing.JLabel areaLabel;
    private javax.swing.JLabel categoryLabel;
    private javax.swing.JPanel categoryList;
    private javax.swing.JButton deleteButton;
    private javax.swing.JLabel descrLabel;
    private javax.swing.JButton exitButton;
    private javax.swing.JLabel headerLabel;
    private javax.swing.JLabel imageLabel;
    private javax.swing.JButton importButton;
    private javax.swing.JLabel infoLabel;
    private javax.swing.JLabel infoResLabel;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JPanel menuPanel;
    private javax.swing.JButton modifyButton;
    private javax.swing.JTextField nameTextField;
    private javax.swing.JLabel phoneLabel;
    private javax.swing.JTextField phoneTextField;
    private javax.swing.JLabel photoLabel;
    private javax.swing.JLabel priceRangeLabel;
    private javax.swing.JLabel resName;
    private javax.swing.JButton updateButton;
    // End of variables declaration//GEN-END:variables
}
